package com.bilibili.servlet;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bilibili.entity.User;
import com.bilibili.service.DataCenterService;
import com.bilibili.service.impl.DataCenterServiceImpl;
import com.fasterxml.jackson.databind.ObjectMapper;
@WebServlet("/dataCenter.do")
public class DataCenterServlet extends HttpServlet{
	DataCenterService dcs = new DataCenterServiceImpl();
	ObjectMapper objectMapper = new ObjectMapper(); 
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		resp.setContentType("application/json;charset=UTF-8");
		String timeRange = req.getParameter("timeRange");
        String dataType = req.getParameter("dataType");
        String category = req.getParameter("category");
        String statVideo = req.getParameter("statVideo");
        String statFen = req.getParameter("statFen");
        String statDay = req.getParameter("statDay");
        String user_id = req.getParameter("userId"); 
//        int userId = ((User)req.getSession().getAttribute("loginUser")).getUserId();
        int userId = 1;
        Map<String, Object> statistics = dcs.getChartData(timeRange, dataType, category,userId);
        Map<String, Object> count = dcs.getStatistics(timeRange, category,userId);
        Map<String, Object> result = new HashMap<>(); 
        result.putAll(statistics);
        result.putAll(count);
        objectMapper.writeValue(resp.getWriter(), result);
	}
}
